var xmlhttp = new XMLHttpRequest();

  xmlhttp.onreadystatechange = function () {

     if (this.readyState == 4 && this.status == 200) {

//   objeto-myObj = "this.responseText" es un STRING 
//   y lo convierte a JSON
     
       var myObj = JSON.parse(this.responseText);
       document.getElementById("demo").innerHTML = 
         "Nombre: ".concat(myObj.name + " Edad: ", myObj.age);
        }
      };

    xmlhttp.open("GET", "../archivo_json.json", true);
    xmlhttp.send();

    

Volver al menu principal